|
Исходный файл C:\WINCE600\PLATFORM\COMMON\SRC\COMMON\KITL\device.c |
Модифицированный файл C:\WINCE600\PLATFORM\PracticeBSP_ARK1370\SRC\COMMON\KITL\device.c |
||
|---|---|---|---|
// |
// |
||
// Copyright (c) Microsoft Corporation. All rights reserved. |
// Copyright (c) Microsoft Corporation. All rights reserved. |
||
// |
// |
||
// |
// |
||
// Use of this source code is subject to the terms of the Microsoft end-user |
// Use of this source code is subject to the terms of the Microsoft end-user |
||
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT. |
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT. |
||
// If you did not accept the terms of the EULA, you are not authorized to use |
// If you did not accept the terms of the EULA, you are not authorized to use |
||
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your |
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your |
||
// install media. |
// install media. |
||
// |
// |
||
//------------------------------------ |
//------------------------------------ |
||
// |
// |
||
// File: device.c |
// File: device.c |
||
// |
// |
||
#include <windows.h> |
#include <windows.h> |
||
#include <nkintr.h> |
#include <nkintr.h> |
||
#include <oal.h> |
#include <oal.h> |
||
#include <oal_kitl.h> |
#include <oal_kitl.h> |
||
|
|
||
//------------------------------------ |
//------------------------------------ |
||
// |
// |
||
// Function: OALKitlPCIInfo |
// Function: OALKitlPCIInfo |
||
#ifdef KITL_PCI |
#ifdef KITL_PCI |
||
static VOID OALKitlPCIInfo( |
static VOID OALKitlPCIInfo( |
||
DEVICE_LOCATION *pDevLoc, UINT32 *pId, UINT64 *pAddress, UINT32 *pIrqPin |
DEVICE_LOCATION *pDevLoc, UINT32 *pId, UINT64 *pAddress, UINT32 *pIrqPin |
||
) { |
) { |
||
PCI_COMMON_CONFIG config; |
PCI_COMMON_CONFIG config; |
||
OAL_DDK_PARAMS params; |
OAL_DDK_PARAMS params; |
||
|
|
||
memset(&config, 0xFF, sizeof(config)); |
memset(&config, 0xFF, sizeof(config)); |
||
*pId = 0xFFFFFFFF; |
*pId = 0xFFFFFFFF; |
||
*pAddress = 0; |
*pAddress = 0; |
||
*pIrqPin = 0; |
*pIrqPin = 0; |
||
|
|
||
params.function = IOCTL_OAL_READBUSDATA; |
params.function = IOCTL_OAL_READBUSDATA; |
||
params.rc = 0; |
params.rc = 0; |
||
params.busData.devLoc = *pDevLoc; |
params.busData.devLoc = *pDevLoc; |
||
params.busData.offset = 0; |
params.busData.offset = 0; |
||
params.busData.length = sizeof(config); |
params.busData.length = sizeof(config); |
||
params.busData.pBuffer = &config; |
params.busData.pBuffer = &config; |
||
|
|
||
if (!OEMIoControl( |
if (!OEMIoControl( |
||
IOCTL_HAL_DDK_CALL, ¶ms, sizeof(params), NULL, 0, NULL |
IOCTL_HAL_DDK_CALL, ¶ms, sizeof(params), NULL, 0, NULL |
||
) || !params.rc) goto cleanUp; |
) || !params.rc) goto cleanUp; |
||
|
|
||
*pId = config.VendorID | (config.DeviceID << 16); |
*pId = config.VendorID | (config.DeviceID << 16); |
||
*pAddress = config.u.type0.BaseAddresses[0]; |
*pAddress = config.u.type0.BaseAddresses[1]; |
||
*pIrqPin = config.u.type0.InterruptPin; |
*pIrqPin = config.u.type0.InterruptPin; |
||
|
|
||
cleanUp: |
cleanUp: |
||
return; |
return; |
||
} |
} |
||
#endif |
#endif |
||
|
|
||
//------------------------------------ |
//------------------------------------ |
||
// |
// |
||
// Function: OALKitlFindDevice |
// Function: OALKitlFindDevice |
||
// |
// |
||
// This function find KITL device at specified location in devices table. |
// This function find KITL device at specified location in devices table. |
||
// Depending on bus type it read device address and interrupt pin and translate |
// Depending on bus type it read device address and interrupt pin and translate |
||
// it to system address space and then to kernel virtual address. |
// it to system address space and then to kernel virtual address. |
||
// |
// |
||
OAL_KITL_DEVICE* OALKitlFindDevice( |
OAL_KITL_DEVICE* OALKitlFindDevice( |
||
DEVICE_LOCATION *pDevLoc, OAL_KITL_DEVICE *pDevice |
DEVICE_LOCATION *pDevLoc, OAL_KITL_DEVICE *pDevice |
||
) { |
) { |
||
BOOL rc = FALSE; |
BOOL rc = FALSE; |
||
UINT32 space, id = 0xFFFFFFFF; |
UINT32 space, id = 0xFFFFFFFF; |
||
UINT64 address; |
UINT64 address; |
||
#ifndef BUILDING_BOOTLOADER // Not building boot loader |
#ifndef BUILDING_BOOTLOADER // Not building boot loader |
||
OAL_DDK_PARAMS params; |
OAL_DDK_PARAMS params; |
||
#endif |
#endif |
||
|
|
||
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
||
"+OALKitlFindDevice(%d/%d/%08x, 0x%08x)\r\n", |
"+OALKitlFindDevice(%d/%d/%08x, 0x%08x)\r\n", |
||
pDevLoc->IfcType, pDevLoc->BusNumber, pDevLoc->LogicalLoc, pDevice |
pDevLoc->IfcType, pDevLoc->BusNumber, pDevLoc->LogicalLoc, pDevice |
||
)); |
)); |
||
|
|
||
// Look for driver in list |
// Look for driver in list |
||
while (pDevice->name != NULL && !rc) { |
while (pDevice->name != NULL && !rc) { |
||
|
|
||
// Is it our device? Then move |
// Is it our device? Then move |
||
if (pDevLoc->IfcType != pDevice->ifcType) { |
if (pDevLoc->IfcType != pDevice->ifcType) { |
||
// Move to next driver |
// Move to next driver |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
|
|
||
// Identify device and read its address/interrupt depends on bus type |
// Identify device and read its address/interrupt depends on bus type |
||
switch (pDevLoc->IfcType) { |
switch (pDevLoc->IfcType) { |
||
case InterfaceTypeUndefined: |
case InterfaceTypeUndefined: |
||
if (pDevLoc->LogicalLoc != pDevice->id) break; |
if (pDevLoc->LogicalLoc != pDevice->id) break; |
||
address = pDevLoc->LogicalLoc; |
address = pDevLoc->LogicalLoc; |
||
rc = TRUE; |
rc = TRUE; |
||
break; |
break; |
||
case Internal: |
case Internal: |
||
if (pDevLoc->LogicalLoc != pDevice->id) break; |
if (pDevLoc->LogicalLoc != pDevice->id) break; |
||
address = pDevLoc->LogicalLoc; |
address = pDevLoc->LogicalLoc; |
||
rc = TRUE; |
rc = TRUE; |
||
break; |
break; |
||
#ifdef KITL_PCI |
#ifdef KITL_PCI |
||
case PCIBus: |
case PCIBus: |
||
OALKitlPCIInfo(pDevLoc, &id, &address, &pDevLoc->Pin); |
OALKitlPCIInfo(pDevLoc, &id, &address, &pDevLoc->Pin); |
||
if (id != pDevice->id) break; |
if (id != pDevice->id) break; |
||
rc = TRUE; |
rc = TRUE; |
||
break; |
break; |
||
#endif |
#endif |
||
} |
} |
||
|
|
||
// If we don't identify device skip it |
// If we don't identify device skip it |
||
if (!rc) { |
if (!rc) { |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
|
|
||
// When interface type is undefined physical address |
// When interface type is undefined physical address |
||
// is equal to logical, so break loop |
// is equal to logical, so break loop |
||
if (pDevLoc->IfcType == InterfaceTypeUndefined) { |
if (pDevLoc->IfcType == InterfaceTypeUndefined) { |
||
pDevLoc->PhysicalLoc = (VOID*)address; |
pDevLoc->PhysicalLoc = (VOID*)address; |
||
break; |
break; |
||
} |
} |
||
|
|
||
// Translate bus address, if it fails skip device |
// Translate bus address, if it fails skip device |
||
// Are we in IO space (1) or memory space (0)? |
// Are we in IO space (1) or memory space (0)? |
||
space = (UINT32)address & 0x1; |
space = (UINT32)address & 0x1; |
||
|
|
||
// Mask off the lowest bit; it just indicates which space we're in. This isn't |
// Mask off the lowest bit; it just indicates which space we're in. This isn't |
||
// actually part of the address |
// actually part of the address |
||
address &= ~0x1; |
address &= ~0x1; |
||
|
|
||
#ifdef BUILDING_BOOTLOADER |
#ifdef BUILDING_BOOTLOADER |
||
if (!OALIoTransBusAddress( |
if (!OALIoTransBusAddress( |
||
pDevLoc->IfcType, pDevLoc->BusNumber, address, &space, &address |
pDevLoc->IfcType, pDevLoc->BusNumber, address, &space, &address |
||
)) { |
)) { |
||
rc = FALSE; |
rc = FALSE; |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
|
|
||
// If address has address above 32bit address space skip device |
// If address has address above 32bit address space skip device |
||
if ((address >> 32) != 0) { |
if ((address >> 32) != 0) { |
||
rc = FALSE; |
rc = FALSE; |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
|
|
||
|
|
||
if (space == 0) { |
if (space == 0) { |
||
// Do mapping to virtual address for memory space |
// Do mapping to virtual address for memory space |
||
pDevLoc->PhysicalLoc = OALPAtoVA((UINT32)address, FALSE); |
pDevLoc->PhysicalLoc = OALPAtoVA((UINT32)address, FALSE); |
||
} |
} |
||
else |
else |
||
{ |
{ |
||
// We're in IO space, no mapping necessary |
// We're in IO space, no mapping necessary |
||
UINT8* pAddress = (UINT8*)address; |
UINT8* pAddress = (UINT8*)address; |
||
pDevLoc->PhysicalLoc = (VOID*)address; |
pDevLoc->PhysicalLoc = (VOID*)address; |
||
} |
} |
||
#else // Not building boot loader |
#else // Not building boot loader |
||
params.function = IOCTL_OAL_TRANSBUSADDRESS; |
params.function = IOCTL_OAL_TRANSBUSADDRESS; |
||
params.transAddress.ifcType = pDevLoc->IfcType; |
params.transAddress.ifcType = pDevLoc->IfcType; |
||
params.transAddress.busNumber = pDevLoc->BusNumber; |
params.transAddress.busNumber = pDevLoc->BusNumber; |
||
params.transAddress.space = space; |
params.transAddress.space = space; |
||
params.transAddress.address = address; |
params.transAddress.address = address; |
||
if (!OEMIoControl( |
if (!OEMIoControl( |
||
IOCTL_HAL_DDK_CALL, ¶ms, sizeof(params), NULL, 0, NULL |
IOCTL_HAL_DDK_CALL, ¶ms, sizeof(params), NULL, 0, NULL |
||
) || !params.rc) { |
) || !params.rc) { |
||
rc = FALSE; |
rc = FALSE; |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
address = params.transAddress.address; |
address = params.transAddress.address; |
||
space = params.transAddress.space; |
space = params.transAddress.space; |
||
|
|
||
// If address has address above 32bit address space skip device |
// If address has address above 32bit address space skip device |
||
if ((address >> 32) != 0) { |
if ((address >> 32) != 0) { |
||
rc = FALSE; |
rc = FALSE; |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
|
|
||
// Do mapping to virtual address for memory space |
// Do mapping to virtual address for memory space |
||
if (space == 0) { |
if (space == 0) { |
||
UINT32 offset; |
UINT32 offset; |
||
UINT8 *pAddress; |
UINT8 *pAddress; |
||
UINT32 pa = (UINT32)address; |
UINT32 pa = (UINT32)address; |
||
|
|
||
offset = pa & (VM_PAGE_SIZE - 1); |
offset = pa & (VM_PAGE_SIZE - 1); |
||
pa &= ~(VM_PAGE_SIZE - 1); |
pa &= ~(VM_PAGE_SIZE - 1); |
||
pAddress = NKPhysToVirt(pa >> 8, FALSE); |
pAddress = NKPhysToVirt(pa >> 8, FALSE); |
||
pAddress += offset; |
pAddress += offset; |
||
|
|
||
pDevLoc->PhysicalLoc = pAddress; |
pDevLoc->PhysicalLoc = pAddress; |
||
} |
} |
||
else |
else |
||
{ |
{ |
||
// We're in IO space, no mapping necessary |
// We're in IO space, no mapping necessary |
||
UINT8* pAddress = (UINT8*)address; |
UINT8* pAddress = (UINT8*)address; |
||
pDevLoc->PhysicalLoc = (VOID*)address; |
pDevLoc->PhysicalLoc = (VOID*)address; |
||
} |
} |
||
#endif |
#endif |
||
// We get all we need |
// We get all we need |
||
break; |
break; |
||
} |
} |
||
|
|
||
// Return NULL if driver wasn't found |
// Return NULL if driver wasn't found |
||
if (!rc) pDevice = NULL; |
if (!rc) pDevice = NULL; |
||
|
|
||
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
||
"-OALKitlFindDevice(pDevice = 0x%08x(%s), PhysicalLoc = 0x%08x)\r\n", |
"-OALKitlFindDevice(pDevice = 0x%08x(%s), PhysicalLoc = 0x%08x)\r\n", |
||
pDevice, (pDevice != NULL) ? pDevice->name : L"", pDevLoc->PhysicalLoc |
pDevice, (pDevice != NULL) ? pDevice->name : L"", pDevLoc->PhysicalLoc |
||
)); |
)); |
||
return pDevice; |
return pDevice; |
||
} |
} |
||
|
|
||
0C |
0C |
||
//------------------------------------ |
//------------------------------------ |
||
// |
// |
||
// Function: OALKitlDeviceName |
// Function: OALKitlDeviceName |
||
// |
// |
||
LPCWSTR OALKitlDeviceName( |
LPCWSTR OALKitlDeviceName( |
||
DEVICE_LOCATION *pDevLoc, OAL_KITL_DEVICE *pDevice |
DEVICE_LOCATION *pDevLoc, OAL_KITL_DEVICE *pDevice |
||
) { |
) { |
||
BOOL rc = FALSE; |
BOOL rc = FALSE; |
||
static WCHAR name[64]; |
static WCHAR name[64]; |
||
LPCWSTR pName = NULL; |
LPCWSTR pName = NULL; |
||
|
|
||
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
||
"+OALKitlDeviceName(%d/%d/%08x, 0x%08x)\r\n", |
"+OALKitlDeviceName(%d/%d/%08x, 0x%08x)\r\n", |
||
pDevLoc->IfcType, pDevLoc->BusNumber, pDevLoc->LogicalLoc, pDevice |
pDevLoc->IfcType, pDevLoc->BusNumber, pDevLoc->LogicalLoc, pDevice |
||
)); |
)); |
||
|
|
||
// Look for driver in list |
// Look for driver in list |
||
while (pDevice->name != NULL && !rc) { |
while (pDevice->name != NULL && !rc) { |
||
|
|
||
// Is it our device? Then move |
// Is it our device? Then move |
||
if (pDevLoc->IfcType != pDevice->ifcType) { |
if (pDevLoc->IfcType != pDevice->ifcType) { |
||
// Move to next driver |
// Move to next driver |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
|
|
||
// Identify device and read its address/interrupt depends on bus type |
// Identify device and read its address/interrupt depends on bus type |
||
switch (pDevLoc->IfcType) { |
switch (pDevLoc->IfcType) { |
||
case Internal: |
case Internal: |
||
if (pDevLoc->LogicalLoc != pDevice->id) break; |
if (pDevLoc->LogicalLoc != pDevice->id) break; |
||
pName = pDevice->name; |
pName = pDevice->name; |
||
rc = TRUE; |
rc = TRUE; |
||
break; |
break; |
||
#ifdef KITL_PCI |
#ifdef KITL_PCI |
||
case PCIBus: |
case PCIBus: |
||
{ |
{ |
||
UINT32 id; |
UINT32 id; |
||
OAL_PCI_LOCATION pciLoc; |
OAL_PCI_LOCATION pciLoc; |
||
|
|
||
pciLoc = *(OAL_PCI_LOCATION*)&pDevLoc->LogicalL |
pciLoc = *(OAL_PCI_LOCATION*)&pDevLoc->LogicalL |
||
id = OALPCIGetId(pDevLoc->BusNumber, pciLoc); |
id = OALPCIGetId(pDevLoc->BusNumber, pciLoc); |
||
if (id != pDevice->id) break; |
if (id != pDevice->id) break; |
||
OALLogPrintf( |
OALLogPrintf( |
||
name, sizeof(name)/sizeof(WCHAR), |
name, sizeof(name)/sizeof(WCHAR), |
||
L"%s @ id %d bus %d dev %d fnc %d", |
L"%s @ id %d bus %d dev %d fnc %d", |
||
pDevice->name, pDevLoc->BusNumber, pciLoc.bus, pciLoc.dev, |
pDevice->name, pDevLoc->BusNumber, pciLoc.bus, pciLoc.dev, |
||
pciLoc.fnc |
pciLoc.fnc |
||
); |
); |
||
pName = name; |
pName = name; |
||
rc = TRUE; |
rc = TRUE; |
||
} |
} |
||
break; |
break; |
||
#endif |
#endif |
||
} |
} |
||
|
|
||
// If we don't identify device skip it |
// If we don't identify device skip it |
||
if (!rc) { |
if (!rc) { |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
|
|
||
// We get all we need |
// We get all we need |
||
break; |
break; |
||
} |
} |
||
|
|
||
|
|
||
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
||
"-OALKitlDeviceName(name = 0x%08x('%s')\r\n", pName, pName |
"-OALKitlDeviceName(name = 0x%08x('%s')\r\n", pName, pName |
||
)); |
)); |
||
return pName; |
return pName; |
||
} |
} |
||
|
|
||
0C |
0C |
||
//------------------------------------ |
//------------------------------------ |
||
// |
// |
||
// Function: OALKitlDeviceType |
// Function: OALKitlDeviceType |
||
// |
// |
||
OAL_KITL_TYPE OALKitlDeviceType( |
OAL_KITL_TYPE OALKitlDeviceType( |
||
DEVICE_LOCATION *pDevLoc, OAL_KITL_DEVICE *pDevice |
DEVICE_LOCATION *pDevLoc, OAL_KITL_DEVICE *pDevice |
||
) { |
) { |
||
BOOL rc = FALSE; |
BOOL rc = FALSE; |
||
OAL_KITL_TYPE type = OAL_KITL_TYPE_NONE; |
OAL_KITL_TYPE type = OAL_KITL_TYPE_NONE; |
||
|
|
||
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
KITL_RETAILMSG(ZONE_KITL_OAL, ( |
||
"+OALKitlDeviceType(%d/%d/%08x, 0x%08x)\r\n", |
"+OALKitlDeviceType(%d/%d/%08x, 0x%08x)\r\n", |
||
pDevLoc->IfcType, pDevLoc->BusNumber, pDevLoc->LogicalLoc, pDevice |
pDevLoc->IfcType, pDevLoc->BusNumber, pDevLoc->LogicalLoc, pDevice |
||
)); |
)); |
||
|
|
||
// Look for driver in list |
// Look for driver in list |
||
while (pDevice->name != NULL && !rc) { |
while (pDevice->name != NULL && !rc) { |
||
|
|
||
// Is it our device? Then move |
// Is it our device? Then move |
||
if (pDevLoc->IfcType != pDevice->ifcType) { |
if (pDevLoc->IfcType != pDevice->ifcType) { |
||
// Move to next driver |
// Move to next driver |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
|
|
||
// Identify device and read its address/interrupt depends on bus type |
// Identify device and read its address/interrupt depends on bus type |
||
switch (pDevLoc->IfcType) { |
switch (pDevLoc->IfcType) { |
||
case Internal: |
case Internal: |
||
if (pDevLoc->LogicalLoc != pDevice->id) break; |
if (pDevLoc->LogicalLoc != pDevice->id) break; |
||
type = pDevice->type; |
type = pDevice->type; |
||
rc = TRUE; |
rc = TRUE; |
||
break; |
break; |
||
#ifdef KITL_PCI |
#ifdef KITL_PCI |
||
case PCIBus: |
case PCIBus: |
||
{ |
{ |
||
UINT32 id; |
UINT32 id; |
||
id = OALPCIGetId( |
id = OALPCIGetId( |
||
pDevLoc->BusNumber, *(OAL_PCI_LOCATION*)&pDevLoc->LogicalL |
pDevLoc->BusNumber, *(OAL_PCI_LOCATION*)&pDevLoc->LogicalL |
||
); |
); |
||
if (id != pDevice->id) break; |
if (id != pDevice->id) break; |
||
type = pDevice->type; |
type = pDevice->type; |
||
rc = TRUE; |
rc = TRUE; |
||
} |
} |
||
break; |
break; |
||
#endif |
#endif |
||
} |
} |
||
|
|
||
// If we don't identify device skip it |
// If we don't identify device skip it |
||
if (!rc) { |
if (!rc) { |
||
pDevice++; |
pDevice++; |
||
continue; |
continue; |
||
} |
} |
||
|
|
||
// We get all we need |
// We get all we need |
||
break; |
break; |
||
} |
} |
||
|
|
||
|
|
||
KITL_RETAILMSG(ZONE_KITL_OAL, ("-OALKitlDeviceType(type = %d)\r\n", type)); |
KITL_RETAILMSG(ZONE_KITL_OAL, ("-OALKitlDeviceType(type = %d)\r\n", type)); |
||
return type; |
return type; |
||
} |
} |
||
|
|
||
//------------------------------------ |
//------------------------------------ |
||
|
|